package org.mspring.platform.dao.query.criterion;

import org.mspring.platform.dao.query.QueryBuilder;
import org.mspring.platform.dao.query.QueryHelper;

/**
 * @author Gao Youbo
 * @since Jan 31, 2012
 */
public class LikeExpression extends SimpleExpression {

    private static final long serialVersionUID = 6836215756097118752L;
    private final MatchMode matchMode;

    protected LikeExpression(String hqlName, String paramKey, String operation, MatchMode matchMode, Class<?> paramClass) {
        super(hqlName, paramKey, operation, paramClass);
        this.matchMode = matchMode;
    }

    protected LikeExpression(String hqlName, Object paramValue, String operation, MatchMode matchMode) {
        super(hqlName, paramValue, operation);
        this.matchMode = matchMode;
    }

    @Override
    protected void setParams(QueryBuilder builder, String value, Class<?> paramClass) {
        builder.getNamedQueryParams().put(QueryHelper.qualifyHql(hqlName), matchMode.toMatchString(value));
        builder.getValidQueryParams().put(paramKey, value);
    }

    @Override
    protected void setParams(QueryBuilder builder, Object value) {
        builder.getNamedQueryParams().put(valuedQualifyHql(hqlName), matchMode.toMatchString(value.toString()));
        builder.getValidQueryParams().put(paramKey, value);
    }

}
